package com.example.accountprovider.tcc;

import io.seata.rm.tcc.api.BusinessActionContext;
import io.seata.rm.tcc.api.BusinessActionContextParameter;
import io.seata.rm.tcc.api.LocalTCC;
import io.seata.rm.tcc.api.TwoPhaseBusinessAction;

import java.math.BigDecimal;

/**
 * @author Kong
 * @date 2021-9-14 15:05
 */
@LocalTCC
public interface IAccountTccAction {
    /**
     * prepare阶段   try
     * @param businessActionContext 上下文
     * @param userId 参数
     * @param balance 参数
     * @return
     */
    @TwoPhaseBusinessAction(name = "accountTccAction",commitMethod = "commitDecreaseAccount",rollbackMethod ="rollbackAccount" )
    boolean prepareDecreaseAccount(BusinessActionContext businessActionContext,
                                   @BusinessActionContextParameter(paramName = "userId")Integer userId,
                                   @BusinessActionContextParameter(paramName = "balance") BigDecimal balance);

    /**
     * 二阶段提交 commit
     * @param businessActionContext
     * @return
     */
    boolean commitDecreaseAccount(BusinessActionContext businessActionContext);

    /**
     * 二阶段回滚  cancel
     * @param businessActionContext
     * @return
     */
    boolean rollbackAccount(BusinessActionContext businessActionContext);
}
